﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Verse;

namespace Miao.Stand
{
    [StaticConstructorOnStartup]//必加，否则静态资源读不了
    public class HeirophantGreenStand : StandPawn
    {
        public override bool IsMeleeStand => false;
        //抄的CompProjectileInterceptor
        private static readonly Material ForceFieldMat = MaterialPool.MatFrom("Other/ForceField", ShaderDatabase.MoteGlow);
        private static readonly MaterialPropertyBlock MatPropertyBlock = new MaterialPropertyBlock();


        public override void InitStandAbility()
        {
            base.InitStandAbility();
            standAbilityTracker.standAbilities.Add(StandAbilityMaker.CreateStandAbility("Radius20EmeraldSpray", this));
        }
        //public bool UseRadius20EmeraldSpray;
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            lerpSize = 0;
            base.DeSpawn(mode);
        }
        public override void TickRare()
        {
            base.TickRare();
        }
        private float lerpSize;
        const float rangeSize = 20;

        protected override void DrawAt(Vector3 drawLoc, bool flip = false)
        {
            base.DrawAt(drawLoc, flip);
            if (CurJobDef == StandJobDefOf.Radius20EmeraldSpray)//这里是泰南的腚眼
            {
                if (lerpSize < rangeSize)
                {
                    lerpSize += 0.1f;
                }
            }
            else
            {
                if (lerpSize > 0) lerpSize -= 0.1f;
            }
            if (lerpSize > 0)
            {
                Vector3 pos = Position.ToVector3Shifted();
                pos.y = AltitudeLayer.MoteOverhead.AltitudeFor();
                MatPropertyBlock.SetColor(ShaderPropertyIDs.Color, Color.green);
                Matrix4x4 matrix = default(Matrix4x4);
                matrix.SetTRS(pos, Quaternion.identity, new Vector3(lerpSize * 2f * 1.16015625f, 1f, lerpSize * 2f * 1.16015625f));
                Graphics.DrawMesh(MeshPool.plane10, matrix, ForceFieldMat, 0, null, 0, MatPropertyBlock);
            }
        }

        public override void ExposeData()
        {
            base.ExposeData();
            Scribe_Values.Look(ref lerpSize, "lerpSize");
        }

    }
}
